﻿using System;
using System.Collections;
using System.Web.UI.WebControls;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Components.Configuration.Settings;
using ASPNETVN.PORTAL.Components.UI.DataTypes;

namespace ASPNETVN.PORTAL.Modules.CONTACT
{
    public partial class Main : PortalModuleControl
    {
        public Main()
        {
            // Define an Array List
            ArrayList list1 = new ArrayList();
            
            // Sắp xếp theo cột.
            list1.Add(new ListItem("Họ tên", "Name"));
            list1.Add(new ListItem("Chức danh", "Role"));
            list1.Add(new ListItem("Email", "Email"));

            ModuleSettingItem sortField = new ModuleSettingItem(new CustomListDataType(list1, "Text", "Value"));
            sortField.Value = "Name";
            sortField.Name = "Sắp xếp theo cột";
            sortField.Description = "Sắp xếp theo cột";
            sortField.Order = 1;
            this.BaseSettings.Add("SortField", sortField);

            // Sắp xếp tăng dần / giảm dần.
            ArrayList list2 = new ArrayList();
            list2.Add(new ListItem("Tăng dần", "ASC"));
            list2.Add(new ListItem("Giảm dần", "DESC"));
            ModuleSettingItem sortDirection = new ModuleSettingItem(new CustomListDataType(list2, "Text", "Value"));
            sortDirection.Value = "ASC";
            sortDirection.Name = "Sắp xếp tăng dần / giảm dần";
            sortDirection.Description = "Sắp xếp tăng dần / giảm dần";
            sortDirection.Order = 2;
            this.BaseSettings.Add("SortDirection", sortDirection);

        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            hfModuleID.Value = this.ModuleID.ToString();
        }

        protected string GetEditURL(int itemID)
        {
            return string.Format("~/Modules/CONTACT/AddEditItem.aspx?tabindex={0}&itemid={1}&mid={2}", this.TabIndex, itemID, this.ModuleID);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                this.ModuleTitle.AddUrl = string.Format("~/Modules/CONTACT/AddEditItem.aspx?tabindex={0}&itemid={1}&mid={2}", this.TabIndex, 0, this.ModuleID);
                GridView1.Sort(this.Settings["SortField"].ToString(), this.Settings["SortDirection"].ToString() == "ASC" ? SortDirection.Ascending : SortDirection.Descending);
            }
        }
    }
}